﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace StandardScriptItems.SimpleControls
{
    public class ScriptItemArgumentSelection : UserControl
    {
        Grid Griddy;
        UIElement InstructionDetails;
        ComboBox arg;

        public ScriptItemArgumentSelection(UIElement instructionDetails, String defaultText, IEnumerable<object> selection)
        {
            Name = "ArgumentPostfix";
            InstructionDetails = instructionDetails;
            arg = new EditableComboBox(defaultText, selection);
            arg.Name = "Argument";
            init(instructionDetails, arg);
        }

        public ScriptItemArgumentSelection(UIElement instructionDetails, IEnumerable<object> selection)
        {
            Name = "ArgumentPostfix";
            InstructionDetails = instructionDetails;
            arg = new LEETComboBox();
            arg.Name = "Argument";
            IEnumerator<object> iter = selection.GetEnumerator();
            if (iter.MoveNext())
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Content = iter.Current.ToString();
                item.IsSelected = true;
                arg.Items.Add(item);

                while (iter.MoveNext())
                {
                    item = new ComboBoxItem();
                    item.Content = iter.Current.ToString();
                    arg.Items.Add(item);
                }
            }
            init(instructionDetails, arg);
        }

        private void init(UIElement left, UIElement right)
        {
            Grid.SetColumn(left, 0);
            Grid.SetColumn(right, 1);
            

            Griddy = new Grid();
            Griddy.Name = "Griddy";
            Griddy.ColumnDefinitions.Add(new ColumnDefinition());
            Griddy.ColumnDefinitions.Add(new ColumnDefinition());
            Griddy.Children.Add(InstructionDetails);
            Griddy.Children.Add(arg);
            Content = Griddy;
        }

        public override string ToString()
        {
            return InstructionDetails.ToString() + " | " + arg.Text;
        }
    }

    
}
